-- magic_bonus
-- Created by zouyb Mar/13/2015
-- 翻开格子奖励属性果
-- 参数列说明：
-- prop[0] : prop_id
-- prop[1] : 每翻开N个格子数
-- prop[2] : 奖励属性果ID
-- prop[3] : 奖励最大数目

return {
    apply = function(prop, baseValue)
        return baseValue;
    end,

    -- 触发
    trigger = function(who, prop, arg)
		local user = who;
	
        local triggerNum = prop[2];
        local itemId = prop[3];
        local maxBonusTimes = prop[4];
			
		-- 已加的数值
		local addPoints = PropStatM.getData1(user, "open_grid_bonus");	
		if addPoints < triggerNum then
			return false;
		end	
		
		-- 已奖励的次数
		local bonusTimes = PropStatM.getData2(user, "open_grid_bonus");	
		if bonusTimes >= maxBonusTimes then
			return false;
		end	

		-- 奖励
        BonusM.doBonus({1, itemId, 1,}, "prop open_grid_bonus");	
			
		-- 累计次数	
		bonusTimes = bonusTimes + 1;
		PropStatM.setData2(user, "open_grid_bonus", bonusTimes);	
		
		-- 剩余点数
		PropStatM.setData1(user, "open_grid_bonus", triggerNum - addPoints);	
        return true;
    end,
    
    record = function(target, prop, path)
        return false;
    end,     
};

